<?php

set_time_limit(0);

require_once "libraries/exportrss.php";

require_once "simplecache.php";

require_once "config.php";

require_once "lang.php";

function feed_data($url)
{
    $key = md5($url);
    $cache = new SimpleCache();
    $cache_mins = 60;
    $cache->setExpiryInterval(60*$cache_mins);
    $feed_data = $cache->get($key);
    if (!$feed_data) {
        $feed = new ExportRSS($url, "2.0");
        $feed_data = $feed->get_data();
        $cache->put($key, serialize($feed_data));
    }
    return $feed_data;
}


function feeds_data($url)
{
    
}

function index_feed_data()
{
    global $cfg;
    
    foreach ($cfg['site']['index_topics'] as $news_cat) {
        
        $news_feeds = $cfg['rss'][$news_cat];
        
?>
        <div class="b">
            <div class="bh"><?=$news_cat?></div>
<?php
            $data_to_print = array();
            
            $feed_data = array();
            
            foreach ($news_feeds as $news_feeds_site=>$feed_url) {
                if (!is_array($feed_url)) {
                    
                    $feed_data = feed_data($feed_url);
                    $data_to_print[] = $feed_data[0];
                    
                } else {
                    foreach ($feed_url as $news_feeds_site2=>$feed_url) {
                        $feed_data = feed_data($feed_url);
                        $data_to_print[] = $feed_data[0];                    
                    }
                }            
            }
        
?>
        <div class="bb">
<?php
            $count = 1;
            if (count($data_to_print)<=1) {
                $data_to_print = $feed_data;
            }
            foreach ($data_to_print as $item)
            {
                if (!trim($item['title'])) {
                    continue;
                }
?>
                <div class="bl">
                    <a href="javascript: void 0" fn="pmi" class="pmi">&nbsp;</a><a href="<?=$item['link']?>"><?=$item['title']?></a>
                    <p class="dp"><?=$item['description']?></p>
                    <p class="dp">Date published:<?=$item['date']?> - </p>
                </div>
<?php        
                $count++;
                if ($count>$cfg['site']['index_list_count']) {
                    break;
                }
            }
?>        
        </div>
        
    </div>
<?php        
    }
}

function get_menu_items()
{

}
